package com.aabte.mp.injector;

import com.baomidou.mybatisplus.entity.TableInfo;
import com.baomidou.mybatisplus.mapper.AutoSqlInjector;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.session.Configuration;

/**
 * MySQL全局删除
 */
public class MySqlInjector extends AutoSqlInjector {

    @Override
    public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
        // 将EmployeeMapper中定义的deleteAll，处理成对应的MappeedStatement对象，加入到configuration对象中
        // 定义SQL语句
        String sql = "DELETE FROM " + table.getTableName();
        // 定义Mapper接口方法名称
        String methodName = "deleteAll";
        // 创建SQLSource对象
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        this.addDeleteMappedStatement(mapperClass, methodName, sqlSource);
    }
}
